package com.hk.mapper;

import com.hk.model.NewsType;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: zhe
 * @Date: 2021/6/16 10:29
 * @Statement: 新闻类型Mapper层接口
 */
public interface INewsTypeMapper extends IBaseMapper<NewsType> {

    @Results(id = "newsTypeMap",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "parentId",column = "parent_id"),
            @Result(property = "gmtCreate",column = "gmt_create"),
            @Result(property = "gmtModified",column = "gmt_modified")
    })
    @Select("select * from news_type")
    @Override
    List<NewsType> findAll(NewsType newsType);

    @Select("select count(1) from news_type")
    @Override
    int count(NewsType newsType);

    @ResultMap("newsTypeMap")
    @Select("select * from news_type where id = #{id} ")
    @Override
    NewsType findById(Integer id);

    List<NewsType> findByParentId(@Param("ids") List<Integer> ids);

    @Insert("insert into news_type value " +
            "(null,#{name},#{parentId},#{gmtCreate},#{gmtModified})")
    @Override
    int save(NewsType newsType);

    @Update("update news_type set " +
            "name=#{name},gmt_modified=#{gmtModified} " +
            "where id = #{id} ")
    @Override
    int update(NewsType newsType);

    /**
     * 通过序号修改所属节点
     * @param t
     * @return
     */
    @Update("update news_type set " +
            "parent_id=#{parentId},gmt_modified=#{gmtModified}" +
            "where id = #{id} ")
    int updateParentId(NewsType t);

    @Delete("delete from news_type where id = #{id} ")
    @Override
    int delete(Integer id);

    int deleteIds(@Param("ids") List<Integer> ids);
}
